

 class Outclass1 {

    public int data1 = 1;
    public int data2 = 2;
    public int data3 = 3;

    static class innerClass{

        public int data4 = 4;
        public int data5 = 5;

        void test(){
            //静态内部类调用外部类的成员只能是静态的
            //非静态的成员访问需要实例化外部类对象
            Outclass1 outclass1 = new Outclass1();
            System.out.println(outclass1.data1);
            System.out.println(outclass1.data2);
            System.out.println(outclass1.data2);
            System.out.println(data4);
            System.out.println(data5);
            System.out.println("test()方法被执行了...");
        }
    }
}
//实例化内部类
 class Outclass {

    public int data1 = 1;
    public int data2 = 2;
    public int data3 = 3;

   class innerClass{

        public int data4 = 4;
        public int data5 = 5;

        void test(){
            //内部类调用外部类的非静态成员
            //外部类类名+this+成员名
            Outclass outclass = new Outclass();
            System.out.println(outclass.data1);
            System.out.println(Outclass.this.data2);
            System.out.println(Outclass.this.data3);
            System.out.println(data4);
            System.out.println(data5);
            System.out.println("test()方法被执行了...");
        }
    }
}
